from .common import *

class ViewGeneratorPage2(wx.adv.WizardPage):
    '''个性化创建视图【第二页】'''
    def __init__(self, parent, title='第二步：定制化个性功能嵌入', out_data = None):
        WizardPageSimple.__init__(self, parent)
        self.next = self.prev = None
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(self.sizer)
        if out_data is not None:
            self.out_data = out_data
            if VIEWS_WIZARD_CONTEXT not in self.out_data:
                self.out_data[VIEWS_WIZARD_CONTEXT] = {}
            self.context = self.out_data[VIEWS_WIZARD_CONTEXT]
            self.context['2'] = {}
            self.context = self.context['2']
        else:
            raise Exception('没有上下文，无法开启向导页面')

        self._init_UI(title)
        self._init_listener()

    def _init_UI(self, title):
        '''初始化界面布局'''
        '''
            设置当前页标题
        '''
        title = wx.StaticText(self, -1, title)
        title.SetFont(wx.Font(16, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
        self.sizer.Add(title, 0, wx.ALIGN_LEFT|wx.ALL, 3)
        self.sizer.Add(wx.StaticLine(self, -1), 0, wx.EXPAND|wx.ALL, 5) # 水平分割线

        '''
            所有的其他控件全部放在滚动面板中
        '''
        self.scollPanel = scrolledpanel.ScrolledPanel(self, -1, size=SIZE) # 定义滚动面板
        self.scollPanel.SetupScrolling() # 开启滚动
        self.scollPanelSizer = wx.BoxSizer(wx.VERTICAL)
        self.scollPanel.SetSizer(self.scollPanelSizer)
        self.sizer.Add(self.scollPanel, 1, wx.EXPAND | wx.ALL, 2) # 加入主容器

        self._init_scollpanel()

    def _init_scollpanel(self):
        '''初始化滚动窗口'''
        # 控件
        self.radioBoxSource = wx.RadioBox(self.scollPanel, -1, '选择功能来源', choices=['本地功能', '云功能'])
        self.scollPanelSizer.Add(self.radioBoxSource, 0, wx.EXPAND|wx.ALL, 1)

    def _init_listener(self):
        """注册监听"""
        self.Bind(wx.adv.EVT_WIZARD_PAGE_CHANGING, self.onWizPageChanging)
        self.Bind(wx.adv.EVT_WIZARD_CANCEL, self.onWizCancel)

    def onWizCancel(self, evt):
        """界面取消时触发"""
        if not RichMsgDialog.showYesNoMsgDialog(self, '【取消】/【关闭】将导致已填的数据全部被丢弃！', "警告"):
            evt.Veto()

    def onWizPageChanging(self, evt):
        """向导页切换时触发"""
        # evt.Veto()

    def SetNext(self, next):
        '''设置后一页'''
        self.next = next

    def SetPrev(self, prev):
        '''设置前一页'''
        self.prev = prev

    def GetNext(self):
        '''获取下一页/下一指定页（当前页点击下一页会触发下一页的 GetNext() 方法）'''
        return self.next

    def GetPrev(self):
        '''获取上一页/上一指定页（当前页点击上一页会触发上一页的 GetNext() 方法）'''
        return self.prev
        